$('#logo').click(function(){
	panel.util.secContentPage('index/index.html',false,true);
});

//扩展easyui表单的验证
$.extend($.fn.validatebox.defaults.rules, {
    isExistLoginId:{
    	validator:function(value,param){
    		var result = false;
    		$.ajax({  
				type : "post",  
				url : "/manage/systemmanage/systemusermanage/UserManage/checkLoginIdIsExsit",
				data : {'userLoginId':value},  
				async : false,  
				success : function(data){  
					eval('var dataJson = '+data);
					result = dataJson.result;
			    }
			});
    		if(result==1)
				return false;
			else
				return true;
    	},
    	message:'该用户不存在'
    },
    myGoldNumber:{
    	validator:function(value,param){
    		var result = false;
    		$.ajax({  
    			type : "post",  
    			url : "/manage/panel/Panel/queryMyGlod",
    			data : {},  
    			async : false,  
    			success : function(data){  
    				eval('var dataJson = '+data);
    				result = dataJson.result;
    			}
    		});
    		var ownGold= parseFloat(result.userGold)-parseFloat(value);
    		if( parseFloat(result.userGold)>parseFloat(value) && ownGold>=1000)
    			return true;
    		else
    			return false;
    		
    	},
    	message:'野猪币不足'
    },
    valLength:{
    	validator:function(value){
    		var result = false;
    		if(value<=1000)
    			return false;
			else
    			return true;
    	},
    	message:'赠送的野猪币不能少于1000'
    }
});
//工具方法
var util = {};
//声音方法
util.sound = {};
util.sound.openLSlide = function(){
	if(isSound){
		var openLSlideSound = new FUI.soundComponent({src:'/sound/open.wav',altSrc:'open.wav'});
		openLSlideSound.play();
	}
	
}
util.sound.closeLSlide = function(){
	if(isSound){
		var closeLSlideSound = new FUI.soundComponent({src:'/sound/close.wav',altSrc:'close.wav'});
		closeLSlideSound.play();
	}
}
util.sound.keyupSound = function(){
	if(isSound){
		var clickSound = new FUI.soundComponent({src:'/sound/click.wav',altSrc:'click.wav'});
		clickSound.play();
	}
}
$(window.document.body).keyup(function(){
	util.sound.keyupSound();
});

util.patch = {};
util.patch.ie6panelFix = function(){
	//如果是IE6进行JS计算面板的高宽
	if($.browser.msie && $.browser.version == 6.0){
		function calculateFrame(){
			var winWidth = $(window).width(),
			winHeight = $(window).height();
			$('#divFrameMainNav').height(winHeight-88);
			$('#secContent').css({
				width:winWidth-201,
				height:winHeight-88
			});
		}
		$(window).resize(function(){
			calculateFrame();
		});
	}
}();
var currentUrl = '';
//面板核心方法
var panel = {};
panel.util = {};
//总菜单选项卡注册功能事件集
var barItemId = Date.parse(new Date());
var barItems = rootMenus;
	
/*[{
	id:'00000000001',
	title:'app管理',
	url:'index/index.html',
	clickEvent:function(){
		panel.analyzeMenuJson(menuIndexList,1);
	},
	isFixed:true
},{
	id:'00000000002',
	title:'数据管理',
	clickEvent:function(){
		panel.analyzeMenuJson(dataManageList);
	},
	isFixed:true
},{
	id:'00000000003',
	title:'系统管理',
	clickEvent:function(){
		panel.analyzeMenuJson(menuWebManageList);
	},
	isFixed:true
}];*/
panel.delBarItemById = function(barItemId){
	for(var i=0;i<barItems.length;i++){
		if(barItems[i].id==barItemId)
			barItems.removeElment(i);
	}
}
panel.makeBarItems = function(barItems){
	var barItemsDiv = $('#divFrameTop .menus ul');
	for(var i=0;i<barItems.length;i++){
		//第一个第一次就要加载出来
		if(i==0)
			$.post('/manage/panel/panel/queryUserVisitMenusByParentMenuId',{'menuParentId':barItems[0].id},function(data){
				eval('var dataJson = '+data);
				panel.analyzeMenuJson(dataJson.menuChildren);
			});
		
		var barItem = $('<li></li>').attr({
			'i':i,
			'url':barItems[i].url?barItems[i].url:'',
			'menuitemId':barItems[i].id
		}).addClass('menu').click(function(){
			
			var _i = $(this).attr('i');
			$(this).parent().find('.menu').removeClass('ui-tab-selected');
			$(this).addClass('ui-tab-selected');
			//单击后一律加载该菜单下的信息
			$.post('/manage/panel/panel/queryUserVisitMenusByParentMenuId',{'menuParentId':barItems[_i].id},function(data){
				eval('var dataJson = '+data);
				panel.analyzeMenuJson(dataJson.menuChildren);
			});
				
			//URL查看
			if(barItems[_i].url)
				panel.util.secContentPage(barItems[_i].url,true);
		}).hover(function(){
			$(this).addClass('ui-tab-hover');
		},function(){
			$(this).removeClass('ui-tab-mousedown').removeClass('ui-tab-hover');
		}).mousedown(function(){
			$(this).addClass('ui-tab-mousedown');	
		}).mouseup(function(){
			$(this).removeClass('ui-tab-mousedown');	
		}).appendTo(barItemsDiv);
		
		if(i==0)
			barItem.addClass('ui-tab-selected');
		
		var barItemSpan = $('<span></span>').text(barItems[i].title).appendTo(barItem);
	}
	
	$('<li></li>').attr('title','点击查看更多').addClass('op').hover(function(){
		$(this).addClass('ui-tab-hover');
	},function(){
		$(this).removeClass('ui-tab-mousedown').removeClass('ui-tab-hover');
	}).mousedown(function(){
		$(this).addClass('ui-tab-mousedown');	
	}).mouseup(function(){
		$(this).removeClass('ui-tab-mousedown');	
	}).html('<b></b>').appendTo(barItemsDiv);
}
panel.makeBarItems(barItems);
//正在加载中
var statusLoad = null;
panel.status = {};
panel.status.loading = function(infoText,completeFun){
	$('#divFrameTop .status').hide();
	$('#divFrameTop .status').fadeIn(300);
	if(statusLoad)window.clearTimeout(statusLoad);
	if(infoText)$('#divFrameTop .status').text(infoText);
	else $('#divFrameTop .status').text('加载中...');
	
	statusLoad = window.setTimeout(function(){
		$('#divFrameTop .status').fadeOut(300,function(){
			if(completeFun)completeFun();
		});
	},4000);
}
var closeOpResult = null;
panel.opResult = function(infoText,status,completeFun){
	$('#divFrameTop .op-result').text(infoText);
	$('#divFrameTop .op-result').css({
		'width':'auto',
		'top':'-26px'
	});
	//如果结果状态存在
	if(status){
		switch(status){
			case 'error':	
				$('#divFrameTop .op-result').addClass('error');
				break;
			default:
				$('#divFrameTop .op-result').removeClass('error');
				break;
		}
	}
	
	$('#divFrameTop .op-result').css('margin-left','-'+$('#divFrameTop .op-result').width()/2+'px').animate({
		'top':0
	},300,function(){
		if(closeOpResult)window.clearTimeout(closeOpResult);
		closeOpResult = window.setInterval(function(){
			$('#divFrameTop .op-result').animate({
				'top':'-26px'
			},function(){
				if(completeFun)completeFun();
			});
		},4000);
	});
}
panel.opResult('加载完成...');

//显示面板核心数据
var consoleCoreData =[{
	url:'index/index.html',
	isFrame:true
},{
	url:'faceselected/faceselected.html',
	isFrame:false
}];

/**
** 开启右部访问连接
**/
panel.util.secContentPage = function(url,isFrame,isDiv){
	//隐藏所有控制台的信息
	$('#secContent .secContentPage').hide();
	//如果URL已经注册到数据中就开启该控制台显示
	for(var i=0;i<consoleCoreData.length;i++){
		if(url==consoleCoreData[i].url){
			$('#secContent .secContentPage[url="'+url+'"]').show();
			$('body').addClass('fixIe6');
			return false;
		}
	}
	
	var itemConsoleCore = {
		'url':url,
		'isFrame':isFrame?isFrame:false
	}
	//创建数据
	consoleCoreData.push(itemConsoleCore);
	//创建HTML的节点
	var secContentPage = $('<div></div>').addClass('secContentPage').attr('url',url).css({
		width:'100%',
		height:'100%'
	}).appendTo('#secContent');
	
	//如果是iframe方式就生成iframe
	if(isFrame){
		var iframe = $('<iframe allowtransparency=true></iframe>').attr({
			'src':url,
			'width':'100%',
			'height':'100%'
		}).load(function(){
			$(this).contents().find('body').css('background','transparent');
			
			$(this).contents().find('body').click(function(){
				$('.ui-pop-select-free').hide();
				$('.ui-single-select-options').hide();
			});
		}).click(function(){
			$('.ui-pop-select-free').hide();
			$('.ui-single-select-options').hide();
		}).appendTo(secContentPage);
	}
	//如果是url请求方式就post请求url
	else{
		if(!isDiv)
			$.post(url,function(data){
				secContentPage.html(data);
			});
	}
}

//通过URL寻找控制的数据和节点进行删除操作
panel.util.delConsoleDataByUrl = function(url){
	for(var i=0;i<consoleCoreData.length;i++){
		if(consoleCoreData[i].url==url)
			consoleCoreData.removeElment(i);
	}
	
	$('#secContent .secContentPage[url="'+url+'"]').remove();
}

//删除菜单节点
panel.util.findRemoveInfoMenu = function(menuListJson,menuId){
	for(var i=0;i<menuListJson.length;i++){
		switch(menuListJson[i].menuType){
			case 1:
				if(menuListJson[i].menuChildren){
					for(var j=0;j<menuListJson[i].menuChildren.length;j++){
						if(menuListJson[i].menuChildren[j].menuId == menuId){
							menuListJson[i].menuChildren.removeElment(j);
							return false;
						}
					}	
				}
			break;	
			case 2:
				if(menuListJson[i].menuChildren){
					for(var j=0;j<menuListJson[i].menuChildren.length;j++){
						if(menuListJson[i].menuChildren[j].boardMenuId == menuId){
							menuListJson[i].menuChildren.removeElment(j);
							return false;
						}
					}	
				}
			break;
			break;
			default:
			break;
		}
	}
}

//找节点
panel.util.findNodeById = function(menuListJson,menuId){
	for(var i=0;i<menuListJson.length;i++){
		if(menuListJson[i].menuId == menuId)	
			return menuListJson[i];
	}
}

//左部菜单条生成策略
//var menuListJson = menulist;
//解析json数据
panel.analyzeMenuJson = function(menuListJson){
	var mainNav = $('#divFrameMainNav .main-nav');
	mainNav.empty();	
	var mainNav = $('#divFrameMainNav .main-nav');
	var addInfo = [];
	var delInfo = [];
	var addCommonMenu = [];
	var delCommonMenu = [];
	var addAlbum = [];
	var delAlbum = [];
	var delAlbumCopy = [];
	for(var i=0;i<menuListJson.length;i++){
		var menuListItem = menuListJson[i];
		var menuCommon = $('<li></li>').addClass('nav').addClass('nav-item')
		.attr({
			'id':'menu'+menuListItem.menuId,
			'nid':menuListItem.menuId
		})
		.click(function(){
			if($(this).hasClass('shrink')){
				$(this).removeClass('shrink');	
				$('#menuChildren'+$(this).attr('nid')).show();
			}
			else{
				$(this).addClass('shrink');	
				$('#menuChildren'+$(this).attr('nid')).hide();
			}
		}).hover(function(){
			$(this).addClass('nav-mouseover');
		},function(){
			$(this).removeClass('nav-mouseover');
		}).appendTo(mainNav);
		
		var menuIco = $('<span></span>').addClass('ico').appendTo(menuCommon);
		var menuText = $('<span></span>').addClass('text').html(menuListItem.menuDesc).appendTo(menuCommon);
		if(menuListItem.menuIsSingle==1){
			menuCommon.addClass('single');	
			var newSingleText = menuListItem.menuDesc.replace('{count}',menuListItem.menuCount);
			menuText.html(newSingleText);
		}
		
		//生成子菜单
		menuCommon.addClass('active');
		
		var menuChildren = $('<li></li>').attr({
			'id':'menuChildren'+menuListItem.menuId,
			'nid':menuListItem.menuId
		}).addClass('children').appendTo(mainNav);
		var menuChildrenId = 'menuChildren'+menuListItem.menuId;
		//寻找孩子节点
		if(menuListItem.menuChildren){
			var menuInfoChildren = menuListItem.menuChildren;
			for(var j=0;j<menuListItem.menuChildren.length;j++){
				var menuChildrenP = $('<p></p>').attr({
					'id':'info'+menuListItem.menuChildren[j].menuId,
					'nid':menuListItem.menuChildren[j].menuId,
					'url':menuListItem.menuChildren[j].menuUrl
				})
				.addClass('nav-item').hover(function(){
					$(this).addClass('nav-mouseover');
				},function(){
					$(this).removeClass('nav-mouseover');
				}).click(function(){
					$(this).parent().parent().find('.children p').removeClass('nav-current');
					$(this).addClass('nav-current');
					if($(this).attr('url'))	{
						panel.util.secContentPage($(this).attr('url'),true);
						panel.addBarItem($(this).attr('url'),$(this).text());	
					}
				})
				.appendTo(menuChildren)
				.text(menuListItem.menuChildren[j].menuDesc);
			}
		}
	}
}

//新增选项卡
panel.addBarItem = function(url,title){
	//首先寻址是否已有注册该url
	for(var n = 0;n<barItems.length;n++){
		if(barItems[n].url == url){
			$('#divFrameTop .menus ul li').removeClass('ui-tab-selected');
			$('#divFrameTop .menus ul li[url="'+url+'"]').addClass('ui-tab-selected');
			return false;	
		}
	}
	var barItemNewId = barItemId++;
	barItems.push({
		'id':barItemNewId,
		'url':url,
		'title':title	
	});
	var barItemsDiv = $('#divFrameTop .menus ul');
	$('#divFrameTop .menus ul li').removeClass('ui-tab-selected');
	var barItem = $('<li></li>').attr('menuitemId',barItemNewId).addClass('active').addClass('ui-tab-selected').addClass('menu').attr({
		'url':url
	}).click(function(){
		$(this).parent().find('.menu').removeClass('ui-tab-selected');
		$(this).addClass('ui-tab-selected');
		
		if($(this).attr('url'))
			panel.util.secContentPage($(this).attr('url'),true);
	}).hover(function(){
		$(this).addClass('ui-tab-hover');
	},function(){
		$(this).removeClass('ui-tab-hover');
	}).insertBefore('#divFrameTop .menus ul .op');
	var spanItem = $('<span></span>').text(title).appendTo(barItem);
	var aItem = $('<a></a>').addClass('ui-tab-close').attr({
		'title':'点击关闭标签',
		'href':'javascript:void(0)'
	}).hover(function(){
		$(this).addClass('ui-tab-close-hover');
	},function(){
		$(this).removeClass('ui-tab-close-hover');
	}).click(function(){
		var menuitemid = $(this).parent().attr('menuitemid');
		for(var i = 0;i<barItems.length;i++){
			if(menuitemid && barItems[i].id == menuitemid){
				//删除注册菜单信息
				barItems.removeElment(i);
				break;	
			}
		}
		//删除菜单节点
		$(this).parent().remove();
		//删除控制台显示数据
		panel.util.delConsoleDataByUrl(url);
		
		//关闭后自动选择后面一个有url的项目
		panel.findUrlItem();
		return false;
	}).appendTo(barItem);
	var aItemSpan = $('<span></span>').addClass('ui-tab-close-transarea').appendTo(aItem);
	var aItemB = $('<b></b>').addClass('ui-tab-close-ico').text('x').appendTo(aItem);

	panel.autoBarItem();
}

//寻找有最后一个有url的项目
panel.findUrlItem = function(){
	for(var i = barItems.length;i>0;i--){
		if(barItems[i-1].url){
			$('#divFrameTop .menus ul li').removeClass('ui-tab-selected');
			$('#divFrameTop .menus ul li[url="'+barItems[i-1].url+'"]').addClass('ui-tab-selected');
			panel.util.secContentPage(barItems[i-1].url,true);
			return false;
		}
	}
}
//面板显示效果事件
panel.effect = function(){	
	//搜索邮件效果事件
	$('#divFrameTop .search .btn').hover(function(){
		$(this).addClass('mouseover');
	},function(){
		$(this).removeClass('mousedown').removeClass('mouseover');
	}).mousedown(function(){
		$(this).addClass('mousedown');
	}).mouseup(function(){
		$(this).removeClass('mousedown');	
	});
	
	//选择皮肤
	$('#faceselected').click(function(){
		panel.util.secContentPage($(this).attr('url'));
	});
	
	//选择皮肤效果事件
	$('.face-cate .faces .face').hover(function(){
		$(this).addClass('mouseover');
		$('body').addClass('fixIe6');
	},function(){
		$(this).removeClass('mouseover');
		$('body').addClass('fixIe6');
	}).click(function(){
		$('.face-cate .faces .face').removeClass('current');
		$(this).addClass('current');
		panel.face.selected($(this).attr('url'),false,true);
	});
	
	//伸缩按钮
	var flexEventTrigger = false;
	$('#flexBtn').hover(function(){
		$(this).addClass('mouseover');
	},function(){
		$(this).removeClass('mouseover');
	}).click(function(){
		if(!flexEventTrigger){
			if($(this).hasClass('open')){
				flexEventTrigger = true;
				util.sound.closeLSlide();
				//收选项卡
				$('#divFrameMainNav,#footer .skin-left,#footer .skin-top-left,#footer .skin-bottom-left').animate({ 
					left:'-200px'
				}, 150,function(){
					$(this).animate({
						left:'-180px'
					},150,function(){
						$(this).animate({
							left:'-200px'
						},100,function(){
							flexEventTrigger = false;
						});
					});
				});
				//开选项卡
				$('#secContent').animate({
					left:'0'
				}, 150,function(){
					$(this).animate({
						left:'20px'
					},150,function(){
						$(this).animate({
							left:'0'
						},100,function(){
							panel.autoConsole();
							if ( $.browser.msie && $.browser.version ==6){
								$(window).resize();
							}
						})
					})
				});
				$(this).removeClass('open').addClass('close');
			}
			else{
				flexEventTrigger = true;
				util.sound.openLSlide();
				$('#divFrameMainNav,#footer .skin-left,#footer .skin-top-left,#footer .skin-bottom-left').animate({ 
					left:'0'
				}, 500);
				$('#secContent').animate({ 
					left:'201px'
				}, 500,function(){
					panel.autoConsole();
					flexEventTrigger = false;
				});
				$(this).removeClass('close').addClass('open');
			}
		}
	});
	
	$('#divFrameTop .info .first').hover(function(){
		$(this).addClass('mouseover');
	},function(){
		$(this).removeClass('mouseover');
	});
	
	$('#baiduMusiz').hover(function(){
		$(this).find('.musizPanel').css({
			width:'965px',
			height:'594px',
			opacity:1
		});
	},function(){
		$(this).find('.musizPanel').css({
			width:0,
			height:0,
			lineHeight:0,
			fontSize:0,
			opacity:0
		});
	});
	
	//结果栏目自动控制居中程序
	$('#divFrameTop .op-result').css('margin-left','-'+$('#divFrameTop .op-result').width()/2+'px');
}();
//自动适应菜单宽度
panel.autoBarItem = function(){
	var itemBars = $('#divFrameTop .menus ul li:not(.op)');
	var itemCount = $('#divFrameTop .menus ul li:not(.op)').length;
	var windowWidth = $(window).width();
	var itemWidth = ((windowWidth-12-30)/itemCount)-28;
	if(itemWidth>93)itemWidth=93;
	itemBars.width(itemWidth);
}
$(window).bind('resize',function(){
	panel.autoBarItem();
});
//IE6自适应面板控制台
panel.autoConsole = function(){
	if ( $.browser.msie && $.browser.version ==6){
		var consoleWidth = 0;
		if($('#flexBtn').hasClass('open'))
			consoleWidth = $(window).width()-200-20;
		else
			consoleWidth = $(window).width()-20;
			
		$('#secContent').width(consoleWidth);
	}
};
						
panel.autoConsole();
$(window).resize(function(){
	panel.autoConsole();
});
//皮肤更换器
panel.face = {};
panel.face.selected = function(url){
	cookie('skinUrl',url , {expires: 30});
	$('#skinSelected').attr('href',url);
	//如果是IE6需要重新修复PNG显示
	if ( $.browser.msie && $.browser.version ==6){
		$('#divFrameTop .logo').empty();
		var a = $('<a></a>').addClass('png_bg').appendTo('#divFrameTop .logo');
		DD_belatedPNG.fix('.png_bg,.png-bg');
	}
}

//效果对象
util.effect = {};
//弹出选项卡效果
util.effect.popselect = function(targetNode,popNode,callback,left,top){
	targetNode.click(function(){
		if(callback)callback(popNode);
		
		var offset = $(this).offset();
		//计算弹出框的左
		
		var x = offset.left+$(this).width()+parseInt($(this).css('padding-left').replace('px',''))+parseInt($(this).css('padding-right').replace('px',''));
		var y = offset.top+$(this).height();
		
		if(left && top){
			var direct = (left>0?'left':'right');
			popNode.addClass('ui-pop-select-free').css({
				'opacity':0,
				direct:left>0?left+'px':-(left)+'px',
				'top':(top-4)+'px'
			}).show().animate({ 
				direct:left>0?left+'px':-(left)+'px',
				'top':(top)+'px',
				opacity:1
			}, 500);	
		}else{
			popNode.addClass('ui-pop-select-free').css({
				'opacity':0,
				'left':(x-popNode.width()+1)+'px',
				'top':(y)+'px'
			}).show().animate({ 
				'left':(x-popNode.width()+1)+'px',
				'top':(y+4)+'px',
				opacity:1
			}, 500);	
		}
	});
}
//关闭自由弹出层开启事件
$(window.document.body).mousedown(function(e){
	var target = $(e.target);
	var result = false;
	for(var i=0;i<15;i++){
		if(target.hasClass('ui-pop-select-free') || target.hasClass('ui-single-select-options') || target.attr('id')=='serach-menu'){
			result = true;
			break;
		}else{
			target = target.parent();	
		}
	}
	if(!result){
		$('.ui-pop-select-free').hide();
		$('#serach-menu').hide();
	}
});	


$('#iframeIndex').load(function(){ //确保子页面完成加载
	$(this).contents().find('body').css('background','transparent');
		
	$(this).contents().find('body').click(function(){
		$('.ui-pop-select-free').hide();
		$('.ui-single-select-options').hide();
	});
	
	//$('#secContent .secContentPage iframe').contents().find('body').click(function(){
	//	alert(123);
	//	$('.ui-pop-select-free').hide();
	//});
});

//导航菜单操作
util.effect.popselect($('#divFrameTop .menus ul .op'),$('#menus_op_tab_options'),function(popNode){
	popNode.empty();
	//生成节点
	var menuitemClose = $('<div></div>').text('关闭全部').click(function(){
		//记录要删除的节点
		var delBarItems = new Array();
		for(var i=0;i<barItems.length;i++){
			if(!barItems[i].isFixed){
				delBarItems.push(barItems[i].id);
			}
		}
		//删除需要删除的节点
		for(var i=0;i<delBarItems.length;i++){
			$('#divFrameTop .menus ul li[menuitemid="'+delBarItems[i]+'"]').remove();
			panel.delBarItemById(delBarItems[i]);
		}
		panel.findUrlItem();
		popNode.hide();
	}).addClass('menuitem').hover(function(){
		$(this).addClass('mouseover');
	},function(){
		$(this).removeClass('mouseover');
	}).appendTo(popNode);
	$('<div></div>').addClass('icon').addClass('close').appendTo(menuitemClose);
	
	//分割线
	$('<div></div>').addClass('dividing-line').appendTo(popNode);
	//计算当前开启菜单的索引
	var currentIndex = $('#divFrameTop .menus ul .ui-tab-selected').index();
	//遍历所有固定的菜单
	for(var i=0;i<barItems.length;i++){
		if(barItems[i].isFixed){
			var menuitem = $('<div></div>').attr('menuitemId',barItems[i].id).text(barItems[i].title).click(function(){
				$('#divFrameTop .menus ul li[menuitemid="'+$(this).attr('menuitemId')+'"]').click();
				popNode.hide();
			}).addClass('menuitem').hover(function(){
				$(this).addClass('mouseover');
			},function(){
				$(this).removeClass('mouseover');
			}).appendTo(popNode);
			
			var menuitemIcon = $('<div></div>').addClass('iconDot').text('●').appendTo(menuitem);
			if(currentIndex==i)menuitem.addClass('current');
		}
	}
	
	//如果有其他菜单进行展开
	var isFirstItem = true;
	for(var i=0;i<barItems.length;i++){
		if(!barItems[i].isFixed){
			if(isFirstItem){
				isFirstItem = false;
				$('<div></div>').addClass('dividing-line').appendTo(popNode);
			}
			var menuitem = $('<div></div>').attr('menuitemId',barItems[i].id).text(barItems[i].title).click(function(){
				$('#divFrameTop .menus ul li[menuitemid="'+$(this).attr('menuitemId')+'"]').click();
				popNode.hide();
			}).addClass('menuitem').hover(function(){
				$(this).addClass('mouseover');
			},function(){
				$(this).removeClass('mouseover');
			}).appendTo(popNode);
			
			var menuitemClose = $('<div></div>').addClass('iconClose').text('x').click(function(){
				for(var i = 0;i<barItems.length;i++){
					if(barItems[i].id == $(this).parent().attr('menuitemid')){
						//删除注册菜单信息
						barItems.removeElment(i);	
						$('#divFrameTop .menus ul li[menuitemid="'+$(this).parent().attr('menuitemId')+'"]').find('.ui-tab-close').click();
					}
				}
				popNode.hide();
				return false;
			}).appendTo(menuitem);
		}
	}
	
	//判断菜单高度，IE6才需要判断
	if($.browser.msie && $.browser.version == 6.0){
		if(popNode.height()>164)popNode.css('height','164px');
		else popNode.css('height','auto');
	}
});
//搜索框弹出选项操作
util.effect.popselect($('#divFrameTop .search .text .arrow'),$('#serach-menu'),function(){
	$.post('/manage/panel/Panel/queryUserMenus',function(data){
		var result = $.parseJSON(data);
		if(result.menus){
			function zTreeOnClick(event, treeId, treeNode) {
			    panel.util.secContentPage('/'+treeNode.menuUrl,true);
			    panel.addBarItem('/'+treeNode.menuUrl,treeNode.name);	
			    $('#serach-menu').hide();
			};
			
			var setting = {
				view: {
					selectedMulti: false
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					onClick: zTreeOnClick
				}
			};
			
			var treeObj = $.fn.zTree.init($("#serach-menu"), setting, result.menus);
			treeObj.expandAll(true);
		}
	});
},-13,43);

//
$('#divFrameTop .search .text .ins').keyup(function(e){
	if($(this).val()!= undefined && $(this).val()!=""){
		$(this).parent().find('label').hide();
	}
	if(e.which == 13){
		searchKeyMenu();
	}
}).blur(function(e){
	if($(this).val()== undefined || $(this).val()==""){
		$(this).parent().find('label').show();
	}
});

$('#divFrameTop .search .btn').click(function(){
	searchKeyMenu();
});

//搜索关键字拥有的菜单信息
function searchKeyMenu(){
	var menuKey = $('#divFrameTop .search .text .ins').val();
	if(menuKey!= undefined && menuKey!=""){
		$.post('/manage/panel/Panel/queryUserMenus',{'menuDesc':menuKey},function(data){
			var result = $.parseJSON(data);
			if(result.menus){
				function zTreeOnClick(event, treeId, treeNode) {
				    panel.util.secContentPage('/'+treeNode.menuUrl,true);
				    panel.addBarItem('/'+treeNode.menuUrl,treeNode.name);	
				    $('#serach-menu').hide();
				};
				
				var setting = {
					view: {
						selectedMulti: false
					},
					data: {
						simpleData: {
							enable: true
						}
					},
					callback: {
						onClick: zTreeOnClick
					}
				};
				
				var treeObj = $.fn.zTree.init($("#serach-menu"), setting, result.menus);
				treeObj.expandAll(true);
			}
		});
		$('#serach-menu').show();
	}
}

//我的账户
//搜索框弹出选项操作
var isSound = true;
util.effect.popselect($('#divFrameTop .info .first'),$('#ui-msg-account'),function(popNode){
	popNode.find('.row:not(.last,.sound)').hover(function(){
		$(this).addClass('mouseover');
	},function(){
		$(this).removeClass('mouseover');
	});
	
	popNode.find('.changeStateSound').unbind('click').bind('click',function(){
		if($(this).hasClass('open')){
			isSound = false;
			$('#ui-msg-account .row img').removeClass('open-sound').addClass('close-sound');
			$(this).removeClass('open').addClass('close');
			$(this).parent().find('s').text('关闭');
			$('#divFrameTop #baiduMusiz .musizPanel').hide();
			$('#divFrameTop #baiduMusiz .musizPanel').remove();
		}else{
			isSound = true;
			$('#ui-msg-account .row img').removeClass('close-sound').addClass('open-sound');
			$(this).removeClass('close').addClass('open');
			$(this).parent().find('s').text('开启');
			$('#divFrameTop #baiduMusiz .musizPanel').show();
			$('#divFrameTop #baiduMusiz').html('<iframe height="594" width="965" scrolling="no" class="musizPanel" src="http://fm.baidu.com" style="display: block; width: 0px; height: 0px;"></iframe>');
			
			if($.browser.msie && $.browser.version == 6.0){
				$(window).reload();
			}
		}
	});
});

/* 
 *　方法:Array.baoremove(dx) 
 *　功能:删除数组元素. 
 *　参数:dx删除元素的下标. 
 *　返回:在原数组上修改数组. 
 */  
Array.prototype.removeElment = function(dx)  
{
	if(isNaN(dx)||dx>this.length){return false;}  
	this.splice(dx,1);  
}

//**************************start首页JS程序**********************************
$('.index-right .main .tab-addons .setting').hover(function(){
	$(this).addClass('setting-mouseover');
},function(){
	$(this).removeClass('setting-mouseover');
});

$('.index-left .main .tab-title .tab-title-main .setting').hover(function(){
	$(this).addClass('setting-mouseover');
},function(){
	$(this).removeClass('setting-mouseover');
});

$('.index-left .main .tab-content .slide-tab .item').hover(function(){
	$(this).addClass('mouseover');
},function(){
	$(this).removeClass('mouseover');
}).click(function(){
	$('.index-left .main .tab-content .slide-tab .item').removeClass('current');
	$(this).addClass('current');
	if(startSlide)window.clearInterval(startSlide);
	
	var index = $('.index-left .main .tab-content .slide-tab .current').index();
	util.slide.showCurrentItem(index);
	util.slide.startSlide();
});

$('.index-left .main .tab-content .content').hover(function(){
	if(startSlide)window.clearInterval(startSlide);
},function(){
	util.slide.startSlide();
});

var startSlide;

//滑动工具
util.slide = {};
util.slide.startSlide = function(){
	startSlide = window.setInterval(function(){
		var index = $('.index-left .main .tab-content .slide-tab .current').index();
		var count = $('.index-left .main .tab-content .content').length;
		if(index>=count-1){
			util.slide.showCurrentItem(0);
			util.slide.slideCurrentItem(0);
		}else{
			util.slide.showCurrentItem(index+1);
			util.slide.slideCurrentItem(index+1);
		}
	},4000);
};
util.slide.startSlide();
util.slide.showCurrentItem = function(i){
	$('.index-left .main .tab-content .content').removeClass('current');
	$('.index-left .main .tab-content .content').eq(i).addClass('current').css('opacity',0).animate({
		'opacity':1
	});
}
util.slide.slideCurrentItem = function(i){
	$('.index-left .main .tab-content .slide-tab .item').removeClass('current');
	$('.index-left .main .tab-content .slide-tab .item').eq(i).addClass('current');
}
util.tab = {};
util.tab.selected = function(i){
	$('.index-left .main .tab-content').hide();
	$('.index-left .main .tab-content').eq(i).show();
	if(i==1){
		$('.index-left .main .tab-content').eq(i).css({
			'height':'auto'
		});
		if($.browser.msie && $.browser.version == 6.0){
			$('.index-left .main .tab-content').eq(i).css({
				'width':$('.index-left .main .tab-title .tab-title-main').width()
			});
		}
	}
}
$(window).resize(function(){
	if($.browser.msie && $.browser.version == 6.0){
		$('.index-left .main .tab-content').eq(1).css({
			'width':$('.index-left .main .tab-title .tab-title-main').width()
		});
	}
});

//选择附加工具条选项卡
util.tab.selectedToolOption = function(i){
	$('.index-right .main .tab-content').hide();
	if(i!=0){
		$('.index-right .main .tab-addons .tab').removeClass('pre');
		$('.index-right .main .tab-addons .tab').eq(i).addClass('pre');
	}
	$('.index-right .main .tab-content').eq(i).show();
}
$('.index-right .main .tab-addons .tab').click(function(){
	var index = $(this).index();
	$('.index-right .main .tab-addons .tab').removeClass('tab-selected');
	$(this).addClass('tab-selected');
	util.tab.selectedToolOption(index);
});

$('.index-left').css('float','left');
$(function(){
	$('.index-left .main .tab-title .tab-title-main .tab-item').click(function(){
		$('.index-left .main .tab-title .tab-title-main .tab-item').removeClass('tab-selected');
		$(this).addClass('tab-selected');
		var index = $(this).index();
		util.tab.selected(index);
	});
	
	$('body').addClass('ie6fix');
});

//天气预报
util.weather = function(){
	
};
//新闻接口
$(function(){
	$('#news_ul div:not(.baidu)').remove();
});

//退出系统提示
$('#exitSystem').click(function(){
	$.messager.confirm('提醒', '你是否确认要退出系统吗?', function(r){
		if(r){
			$.post('/manage/login/login/quitLogin',function(){
				window.location.reload();
			});
		}
	});
});

//检查用户是否已经没有登录帐号信息了
checkLogin = window.setInterval(function(){
	$.post('/manage/login/login/checkUserLogin',function(data){
		var resultObj = $.parseJSON(data);
		if(resultObj.result==0){
			$.messager.confirm('重新登录提示', '您的帐号登录信息已经过期，为了您的安全系统请您重新登录!', function(r){
				if (r){
					window.location.reload();
				}else{
					window.clearInterval(checkLogin);
				}
			});
		}
	});
},1000*60);

//修改用户密码(管理员)
function updateUserPwd(userId){
	//打开权限设置弹出框
	$('#updateUserPwd').dialog('open');
	//先清空后加载
	$('#updateUserPwdForm').form('clear');
	//每次打开要把roleId传入角色菜单弹出框信息里面去
	$('#updateUserPwdForm input[name="userId"]').val(userId);
}
//修改用户密码（个人）
function updatePwd(){
	//打开权限设置弹出框
	$('#updatePwd').dialog('open');
	//先清空后加载
	$('#updatePwdForm').form('clear');
}

//编辑用户信息
function updateUserInfo(userId){
	//打开权限设置弹出框
	$('#updateUser').dialog('open');
	//先清空后加载
	$('#updateUserForm').form('clear');
	//每次打开要把roleId传入角色菜单弹出框信息里面去
	$('#updateUserForm input[name="userId"]').val(userId);
	$.post('/manage/systemmanage/systemusermanage/UserManage/getUserById', { 'userId':userId } ,function(data){
		eval('var dataJson = '+data);
		if(dataJson.userInfo.photoNoExtUrl)
			var img = $('<img src="'+SITE_GLOBAL_URL+dataJson.userInfo.photoNoExtUrl+"_100x100."+dataJson.userInfo.photoExt+'"/>')
		$('#showUpdateUserPhoto').empty();
		$('#showUpdateUserPhoto').append(img);
		$('#updateUserForm').form('load', dataJson.userInfo);
		$("#uploadUpdateAvater").uploadify({
			'height': 20,
			'fileObjName': 'files',
			'multi': false,
			'formData': {'albumId':3,'photoIsOffic':1,'photoType':4,'sessionId':sessionId},
			'buttonText': '　　上传头像',
			'buttonClass': 'uploadAvaterBtn icon-image',
			'swf': SITE_GLOBAL_URL + '/plug/uploadify/uploadify.swf',
			'uploader': SITE_GLOBAL_URL + '/manage/album/album/uploadAlbum',
			'width': 80,
			'onUploadSuccess': function (file, data, response) {
				data = $.parseJSON(data);
				if (response) {
					if (data.state == 'SUCCESS') {
						$('#showUpdateUserPhoto').empty();
						if(data.photoNoExtUrl){
							var img = $('<img src="'+data.photoNoExtUrl + "_100x100." + data.fileExt+'"/>');
							$('#showUpdateUserPhoto').append(img);
							$('#updateUserForm input[name="userAvatarId"]').val(data.photoId);
						}
					} else {
						$.alertDialog(data.message);
					}
				} else {
					$.alertDialog("发生网络错误");
				}
			}
		});
	});
}

//**************************end首页JS程序**********************************